﻿using System.Data;
using DataAccessDAL;
using MySql.Data.MySqlClient;
namespace HGP_QLKH002.HGP_QLKH002.BUS
{
    class QLKHBUS
    {
        private DataAccessDAL.AcessData ac;
        public QLKHBUS()
        {
            ac =new AcessData();
        }

        public DataTable GetorderID()
        {
            string sql = "SELECT wp_postmeta.post_id, wp_postmeta.meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = @metakey ORDER BY wp_postmeta.post_id ASC";
            MySqlParameter[] param = new MySqlParameter[1];
            param[0] = new MySqlParameter("@metakey", MySqlDbType.VarChar);
            param[0].Value = "orderID";
            DataTable dt = ac.GetDataSet(sql, param, false).Tables[0];
            return dt;
        }

        public DataTable Gettenkh()
        {
            string sql = "SELECT wp_postmeta.post_id, wp_postmeta.meta_value FROM wp_postmeta WHERE wp_postmeta.meta_key = @metakey ORDER BY wp_postmeta.post_id ASC";
            MySqlParameter[] param = new MySqlParameter[1];
            param[0] = new MySqlParameter("@metakey", MySqlDbType.VarChar);
            param[0].Value = "ten_khach_hang";
            DataTable dt = ac.GetDataSet(sql, param, false).Tables[0];
            return dt;
        }

        public DataTable GetTenByMa(string value, int id)
        {
            string sql = "SELECT DISTINCT wp_postmeta.meta_value FROM wp_postmeta WHERE "+
                "wp_postmeta.meta_key = @metakey AND wp_postmeta.post_id = @id";
            MySqlParameter[] param = new MySqlParameter[2];
            param[0] = new MySqlParameter("@metakey", MySqlDbType.VarChar);
            param[0].Value = value;

            param[1] = new MySqlParameter("@id", MySqlDbType.VarChar);
            param[1].Value = id;
            DataTable dt = ac.GetDataSet(sql, param, false).Tables[0];
            return dt;
        }
    }
}
